package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 地址数据层接口
 */
@Mapper
public interface AddressBookMapper {

    /**
     * 通过当前登录的用户ID获取当前用户的地址
     * @param addressBook
     * @return
     */
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 通过地址ID获取地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getAddressBookById(Long id);

    /**
     * 新增地址
     * @param addressBook
     */
    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) VALUES" +
            " (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void saveAddress(AddressBook addressBook);

    /**
     * 更新地址
     * @param book
     */
    void update(AddressBook book);

    /**
     * 通过ID删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteAddressById(Long id);
}
